package com.aws.xml;

import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

/**
 * @description:
 * @author: libugu@cskaoyan.com
 * @date 2024/1/17 - 11:05
 */
@Component
public class XmlDemo01 {

    @Autowired
    AmazonS3 s3Client;

    public void test1(){
        String bucketName = "mylibugu";
        String key = "xml/test/aaa.xml";
        String content = "your-content";

        InputStream inputStream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
        long contentLength = content.getBytes(StandardCharsets.UTF_8).length;

        PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, inputStream, null);
        putObjectRequest.setMetadata(new ObjectMetadata());
        putObjectRequest.getMetadata().setContentLength(contentLength);

        s3Client.putObject(putObjectRequest);
        System.out.println("xml 完成");
    }

}
